package com.syg.servlet01;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Servlet 入门
 */
public class _01_ServletStart extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 1、使用OutputStream流向浏览器输出"中国"这两个汉字(字节流)
         */
        OutputStream os = resp.getOutputStream();
        //OutputStream os = new FileOutputStream("http://localhost:8082/JavaServlet/entrance");这个方式不行
        os.write("中国".getBytes());
        os.write(1);//流在网络中传输应以字符串传输(字节或字符)的形式传输

        /**
         * 2、使用字符流向浏览器输出"中国"这两个汉字(字符流)——输出流对象,只能获取一次
         */
        //PrintWriter out = resp.getWriter();
        //out.println("Servlet start");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
